package com.bingo.datasecurity.config;

import com.bingo.datasecurity.interceptor.MybatisDecryptInterceptor;
import com.bingo.datasecurity.interceptor.MybatisEncryptInterceptor;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

/**
 * 将自定义的插件加入mybatis拦截器
 *
 * @author bingo
 * @date 2024/1/30 16:35
 */
@Component
public class MybatisInterceptorConfig {

    @Resource
    private SqlSessionFactory sqlSessionFactory;


    @PostConstruct
    public void addInterceptor() {
        Configuration sqlSessionFactoryConfiguration = sqlSessionFactory.getConfiguration();
        sqlSessionFactoryConfiguration.addInterceptor(new MybatisEncryptInterceptor());
        sqlSessionFactoryConfiguration.addInterceptor(new MybatisDecryptInterceptor());
    }
}
